﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Collections;

namespace Acsys.Entity
{
    public class Currency : IEntity
    {
        public int ID = 0;
        public string CODE = "D00000";
        public string NAME = "";
        public double RATE_TO_BASE = 1;

        public Currency()
        {
        }
        public Currency(int id)
        {
            ID = id;
        }
        public Currency(int id, string code)
        {
            ID = id;
            CODE = code;
        }
        public IEntity Get(MySqlDataReader aReader)
        {
            Currency ccy = null;
            while (aReader.Read())
            {
                ccy = new Currency();
                ccy.ID = Convert.ToInt32(aReader[0]);
                ccy.CODE = aReader[1].ToString();
                ccy.NAME = aReader[2].ToString();
                ccy.RATE_TO_BASE = Convert.ToDouble(aReader[3]);
            }
            aReader.Close();
            return ccy;
        }
        public string GetInsertSQL()
        {
            return String.Format(@"insert into table_currency 
                (ccy_code,ccy_name,ccy_ratetobase) 
                VALUES ('{0}','{1}',{2})",
                CODE, NAME,RATE_TO_BASE);
        }
        public string GetDeleteSQL()
        {
            return "delete from table_currency where ccy_id = " + ID;
        }
        public string GetUpdateSQL()
        {
            return String.Format(@"update table_currency set 
                ccy_code = '{0}', 
                ccy_name='{1}',
                ccy_ratetobase={2}
                where ccy_id = {3}",
                CODE, NAME, RATE_TO_BASE, ID);
        }
        public string GetByIDSQL(int ID)
        {
            return String.Format("select * from table_currency where ccy_id = {0}", ID);
        }
        public string GetByCodeSQL(string code)
        {
            return String.Format("select * from table_currency where ccy_code = '{0}'", code);
        }
        public string GetByCodeLikeSQL(string text)
        {
            return String.Format("select * from table_currency where ccy_code like '%{0}%'", text);
        }
        public string GetByNameLikeSQL(string text)
        {
            return String.Format("select * from table_currency where ccy_name like '%{0}%'", text);
        }
        public string GetAllSQL()
        {
            return String.Format("select * from table_currency");
        }
        public IList GetAll(MySqlDataReader aReader)
        {
            IList result = new ArrayList();
            while (aReader.Read())
            {
                Currency ccy = new Currency();
                ccy.ID = Convert.ToInt32(aReader[0]);
                ccy.CODE = aReader[1].ToString();
                ccy.NAME = aReader[2].ToString();
                ccy.RATE_TO_BASE = Convert.ToDouble(aReader[3]);
                result.Add(ccy);
            }
            aReader.Close();
            return result;
        }
        public int GetID()
        {
            return ID;
        }
        public void SetID(int id)
        {
            ID = id;
        }
        public override string ToString()
        {
            return CODE;
        }
        public string GetCode()
        {
            return CODE;
        }
        public void SetCode(string code)
        {
            CODE = code;
        }
        public string GetMaximumIDSQL()
        {
            return String.Format("SELECT max(ccy_id) from table_currency");
        }
    }
}
